const express = require('express') //引入express
const path = require('path');
const mysql = require('mysql'); //引入MYSQL模块

//创建应用
const app = express();
//开放端口号
const port = 3000;



//配置模板引擎art-template
app.engine('html', require('express-art-template'));
//托管静态文件
app.set('views', path.join(__dirname, 'views'));
//设置视图引擎
app.set('view engine', 'html');
//使用node_modules下依赖项
app.use('/node_modules', express.static(path.join(__dirname, './node_modules')));
//使用public静态资源
app.use('/public', express.static(path.join(__dirname, 'public')));
app.use('/dist', express.static(path.join(__dirname, 'dist')));


//浏览器跨域请求设置
// app.all('*', function(req, res, next) {
//   res.header("Access-Control-Allow-Origin", "*");
//   res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
//   res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
//   res.header("X-Powered-By",' 3.2.1')
//   if(req.method=="OPTIONS") res.send(200);
//   else  next();
// });


//引入自定义模块
const UIRoutes = require('./routes/UIRoutes');
const indexPageSQL = require('./routes/serviceModules/indexPageSQL'); //城市信息查询模块
const connection = require('./routes/SQLModules/dbConnection');


//引用路由对象
app.use(UIRoutes()); //页面跳转模块
app.use(indexPageSQL()); //城市信息查询模块



//监听端口
app.listen(port, () => {
    console.log("启动成功");
})